var levelOrder = function (root) {
    const queue = []
    queue.push(root)
    const res =[]
    while (queue.length) {
        const arr = []
        const len = queue.length
        for(let i = 0;i<len;i++){
            const top = queue[0]
            arr.push(top.val)
            if (top.left) {
                queue.push(top.left)
            }
            if (top.right) {
                queue.push(top.right)
            }
            queue.shift()
        }
        res.push(arr)
    }
};